V=$(shell cat VERSION)
P=$(shell pwd)
A=$(shell sed -n '1p' .env)
B=$(shell sed -n '2p' .env)
C=$(shell sed -n '3p' .env)
D=$(shell sed -n '4p' .env)
E=$(shell sed -n '5p' .env)
F=$(shell sed -n '6p' .env)

.PHONY: install
install:
	pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \
		-r requirements.txt

.PHONY: runserver
runserver:
	touch "${D}.memory-card.json"
	docker run -itd --name bot-server \
		-v "`pwd`/${D}.memory-card.json":"/wechaty/${D}.memory-card.json" \
		-e WECHATY_LOG=$(A) \
		-e WECHATY_PUPPET=$(B) \
		-e WECHATY_PUPPET_SERVER_PORT=$(C) \
		-e WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER=$(E) \
		-e WECHATY_TOKEN=$(D) \
		-p $(C):$(C) \
		wechaty/wechaty:0.65

.PHONY: runbot
runbot:
	docker run -it --name bot-py \
		-p 8004:8004 \
		-v $(P)/main:/bot/main \
		-e WECHATY_PUPPET_SERVICE_ENDPOINT='$(F):$(C)' \
		chatbot-py:$(V)

.PHONY: run
run: runserver runbot
	echo 'Running...'

.PHONY: build
build:
	docker build -t chatbot-py:$(V) .
